## 
## TODO: For now, use the default repository when calling Saxon.  Must
## use a dedicated repo only for tests (somewhere in bin/ or something).
## 

SAXON=/Users/fgeorges/bin/saxon
CALABASH=/Users/fgeorges/bin/calabash
XSPEC=/Users/fgeorges/projects/xslt/xspec/trunk/xspec.sh
XSPEC.xsl=/Users/fgeorges/projects/xslt/xspec/trunk/generate-xspec-tests.xsl
XSPEC.xq=/Users/fgeorges/projects/xslt/xspec/trunk/generate-query-tests.xsl
XSPEC.report=/Users/fgeorges/projects/xslt/xspec/trunk/format-xspec-report.xsl
XSPEC.home=file:///Users/fgeorges/projects/xslt/xspec/trunk
SAXON.xsl.harness=http://www.jenitennison.com/xslt/xspec/saxon/harness/xslt.xproc
SAXON.xq.harness=http://www.jenitennison.com/xslt/xspec/saxon/harness/xquery.xproc
EXIST.lib_at=xmldb:exist:///db/xspec/generate-query-utils.xql
EXIST.harness=http://www.jenitennison.com/xslt/xspec/exist/harness/xquery.xproc
BASEX.std.harness=http://www.jenitennison.com/xslt/xspec/basex/harness/standalone/xquery.xproc
BASEX.server.harness=http://www.jenitennison.com/xslt/xspec/basex/harness/server/xquery.xproc
ZORBA.harness=http://www.jenitennison.com/xslt/xspec/zorba/harness/xquery.xproc

all: http-client

http-client: http-client-saxon-xsl       \
             http-client-saxon-xq        \
             http-client-exist-xq        \
             http-client-basex-std-xq    \
             http-client-basex-server-xq \
             http-client-zorba-xq

http-client-saxon-xsl: headers-saxon-xsl \
                       method-saxon-xsl  \
                       serial-saxon-xsl  \
                       xproc-http-request-saxon-xsl

http-client-saxon-xq: headers-saxon-xq \
                      method-saxon-xq  \
                      serial-saxon-xq  \
                      xproc-http-request-saxon-xq

http-client-exist-xq: headers-exist-xq \
                      method-exist-xq  \
                      serial-exist-xq  \
                      xproc-http-request-exist-xq

http-client-basex-std-xq: headers-basex-std-xq \
                          method-basex-std-xq  \
                          serial-basex-std-xq  \
                          xproc-http-request-basex-std-xq

http-client-basex-server-xq: headers-basex-server-xq \
                             method-basex-server-xq  \
                             serial-basex-server-xq  \
                             xproc-http-request-basex-server-xq

http-client-zorba-xq: headers-zorba-xq \
                      method-zorba-xq  \
                      serial-zorba-xq  \
                      xproc-http-request-zorba-xq

define saxon-xsl
  "$(CALABASH)" -i source=$(1).xspec \
      -o result=$(1)-saxon-xsl.html \
      "$(SAXON.xsl.harness)" \
      xspec-home="$(XSPEC.home)/"
endef

define saxon-xq
  "$(CALABASH)" -i source=$(1).xspec \
      -o result=$(1)-saxon-xq.html \
      "$(SAXON.xq.harness)" \
      xspec-home="$(XSPEC.home)/"
endef

define exist-xq
  "$(CALABASH)" -i source=$(1).xspec \
      -o result=$(1)-exist-xq.html \
      "$(EXIST.harness)" \
      xspec-home="$(XSPEC.home)/" \
      utils-lib="$(EXIST.lib_at)"
endef

define basex-std-xq
  "$(CALABASH)" -D -i source=$(1).xspec \
      -o result=$(1)-basex-std-xq.html \
      "$(BASEX.std.harness)" \
      xspec-home="$(XSPEC.home)/"
endef

define basex-server-xq
  "$(CALABASH)" -i source=$(1).xspec \
      -o result=$(1)-basex-server-xq.html \
      "$(BASEX.server.harness)" \
      xspec-home="$(XSPEC.home)/"
endef

define zorba-xq
  "$(CALABASH)" -i source=$(1).xspec \
      -o result=$(1)-zorba-xq.html \
      "$(ZORBA.harness)" \
      xspec-home="$(XSPEC.home)/"
endef

headers-saxon-xsl:
	$(call saxon-xsl,headers)

headers-saxon-xq:
	$(call saxon-xq,headers)

headers-exist-xq:
	$(call exist-xq,headers)

headers-basex-std-xq:
	$(call basex-std-xq,headers)

headers-basex-server-xq:
	$(call basex-server-xq,headers)

headers-zorba-xq:
	$(call zorba-xq,headers)

method-saxon-xsl:
	$(call saxon-xsl,method)

method-saxon-xq:
	$(call saxon-xq,method)

method-exist-xq:
	$(call exist-xq,method)

method-basex-std-xq:
	$(call basex-std-xq,method)

method-basex-server-xq:
	$(call basex-server-xq,method)

method-zorba-xq:
	$(call zorba-xq,method)

serial-saxon-xsl:
	$(call saxon-xsl,serial)

serial-saxon-xq:
	$(call saxon-xq,serial)

serial-exist-xq:
	$(call exist-xq,serial)

serial-basex-std-xq:
	$(call basex-std-xq,serial)

serial-basex-server-xq:
	$(call basex-server-xq,serial)

serial-zorba-xq:
	$(call zorba-xq,serial)

xproc-http-request-saxon-xsl:
	$(call saxon-xsl,xproc-http-request)

xproc-http-request-saxon-xq:
	$(call saxon-xq,xproc-http-request)

xproc-http-request-exist-xq:
	$(call exist-xq,xproc-http-request)

xproc-http-request-basex-std-xq:
	$(call basex-std-xq,xproc-http-request)

xproc-http-request-basex-server-xq:
	$(call basex-server-xq,xproc-http-request)

xproc-http-request-zorba-xq:
	$(call zorba-xq,xproc-http-request)

clean:
	rm -f headers-saxon-xsl.html
	rm -f headers-saxon-xq.html
	rm -f headers-exist-xq.html
	rm -f headers-basex-std-xq.html
	rm -f headers-basex-server-xq.html
	rm -f headers-zorba-xq.html
	rm -f method-saxon-xsl.html
	rm -f method-saxon-xq.html
	rm -f method-exist-xq.html
	rm -f method-basex-std-xq.html
	rm -f method-basex-server-xq.html
	rm -f method-zorba-xq.html
	rm -f serial-saxon-xsl.html
	rm -f serial-saxon-xq.html
	rm -f serial-exist-xq.html
	rm -f serial-basex-std-xq.html
	rm -f serial-basex-server-xq.html
	rm -f serial-zorba-xq.html
	rm -f xproc-http-request-saxon-xsl.html
	rm -f xproc-http-request-saxon-xq.html
	rm -f xproc-http-request-exist-xq.html
	rm -f xproc-http-request-basex-std-xq.html
	rm -f xproc-http-request-basex-server-xq.html
	rm -f xproc-http-request-zorba-xq.html

.PHONY: all                                \
        clean                              \
        http-client                        \
        http-client-saxon-xsl              \
        http-client-saxon-xq               \
        http-client-exist-xq               \
        http-client-basex-std-xq           \
        http-client-basex-server-xq        \
        http-client-zorba-xq               \
        headers                            \
        headers-saxon-xsl                  \
        headers-saxon-xq                   \
        headers-exist-xq                   \
        headers-basex-std-xq               \
        headers-basex-server-xq            \
        headers-zorba-xq                   \
        method                             \
        method-saxon-xsl                   \
        method-saxon-xq                    \
        method-exist-xq                    \
        method-basex-std-xq                \
        method-basex-server-xq             \
        method-zorba-xq                    \
        serial                             \
        serial-saxon-xsl                   \
        serial-saxon-xq                    \
        serial-exist-xq                    \
        serial-basex-std-xq                \
        serial-basex-server-xq             \
        serial-zorba-xq                    \
        xproc-http-request                 \
        xproc-http-request-saxon-xsl       \
        xproc-http-request-saxon-xq        \
        xproc-http-request-exist-xq        \
        xproc-http-request-basex-std-xq    \
        xproc-http-request-basex-server-xq \
        xproc-http-request-zorba-xq
